package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.StockLog;
import com.dkd.manage.service.IStockLogService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 库存变动日志Controller
 * 
 * @author LQL
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/manage/stocklog")
public class StockLogController extends BaseController
{
    @Autowired
    private IStockLogService stockLogService;

    /**
     * 查询库存变动日志列表
     */
    @PreAuthorize("@ss.hasPermi('manage:stocklog:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockLog stockLog)
    {
        startPage();
        List<StockLog> list = stockLogService.selectStockLogList(stockLog);
        return getDataTable(list);
    }

    /**
     * 导出库存变动日志列表
     */
    @PreAuthorize("@ss.hasPermi('manage:stocklog:export')")
    @Log(title = "库存变动日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockLog stockLog)
    {
        List<StockLog> list = stockLogService.selectStockLogList(stockLog);
        ExcelUtil<StockLog> util = new ExcelUtil<StockLog>(StockLog.class);
        util.exportExcel(response, list, "库存变动日志数据");
    }

    /**
     * 获取库存变动日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:stocklog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(stockLogService.selectStockLogByLogId(logId));
    }

    /**
     * 新增库存变动日志
     */
    @PreAuthorize("@ss.hasPermi('manage:stocklog:add')")
    @Log(title = "库存变动日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockLog stockLog)
    {
        return toAjax(stockLogService.insertStockLog(stockLog));
    }

    /**
     * 修改库存变动日志
     */
    @PreAuthorize("@ss.hasPermi('manage:stocklog:edit')")
    @Log(title = "库存变动日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockLog stockLog)
    {
        return toAjax(stockLogService.updateStockLog(stockLog));
    }

    /**
     * 删除库存变动日志
     */
    @PreAuthorize("@ss.hasPermi('manage:stocklog:remove')")
    @Log(title = "库存变动日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(stockLogService.deleteStockLogByLogIds(logIds));
    }
}
